<?php
/**
* Model Class
* 
* @author Guillermo Landín
* @link 
*/ 

class Pageheadersmodel extends Model {

    function __construct()
    {
        parent::Model();
        
        $this->CI =& get_instance(); 
    }
             
    function get_header($page = NULL){
    
         $this->db->select('Title_Pageheaders as title, Introduction_Pageheaders as intro, Description_Pageheaders as description')
                ->from('pageheaders')
                ->where('id_Pageheaders', $page);

        $query = $this->db->get();
        $result = $query->row_array();

        return $result;
    
    }
             
    function get_content($id = NULL){
    
         $this->db->select('*')
                ->from('pageheaders')
                ->where('id_Pageheaders', $id);

        $query = $this->db->get();
        $result = $query->row_array();

        return $result;
    
    }

    function admin_get_all($fields = '*'){
    
         $this->db->select($fields)
                ->from('pageheaders');

        $query = $this->db->get();
        $result = $query->result_array();

        return $result;
    
    }
 
/***********************************
*   Backoffice functions
***********************************/

    //returns the list of pageheaders
    function admin_get_list($fields='*'){
    
        $this->db->select($fields)
                ->from('pageheaders')
                ->order_by('id_Pageheaders');  

        $query = $this->db->get();

        $result = $query->result_array();
                                 
        return $result;

    }  
    public function admin_get_item($id=FALSE, $fields='*'){

        $this->db->select($fields)
                ->from('pageheaders')       
                ->where('id_Pageheaders', $id);  
        
        $query = $this->db->get();
        return $query->row_array();

    }  
    public function admin_update($id=FALSE, $data=array()){

        $this->db->where('id_Pageheaders', $id)
                ->update('pageheaders', $data); 

    }                      
    public function admin_insert($data=array()){

        //$data["id_Pageheaders"] = uniqid();
        $this->db->insert('pageheaders', $data); 
        return $this->db->insert_id();

    }  
    public function admin_delete($id=FALSE){

        $this->db->where('id_Pageheaders', $id);
        $this->db->delete('pageheaders'); 

    } 
    public function is_duplicated($field, $value, $id=FALSE)
    {
    
        $this->db->select('count(1) as counter')
                ->from('pageheaders')
                ->where($field, $value);        
        if($id!==FALSE) $this->db->where('id_Pageheaders !=', $id);
    
        $query = $this->db->get();
        $row = $query->row_array();
        if($row == NULL)
            return FALSE;
        
        if($row["counter"] > 0){
            return TRUE;
        }else{
            return FALSE;
        }

    } 


}
    
    
/* End of file newsmodel.php */
/* Location: ./system/application/models/newsmodel.php */ 
